*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** FIGURE A24
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~	

use data/processed/data_1, clear

gen riskshare_retirwealth_Jan201=riskshare_retirwealth_Jan20
gen riskshare_ofinwealth_Jan201=riskshare_ofinwealth_Jan20
replace riskshare_retirwealth_Jan201=0 if retirJan20_0==1
replace riskshare_ofinwealth_Jan201=0 if ofinJan20_0==1
gen stockinvestor_retire=riskshare_retirwealth_Jan201>0 if riskshare_retirwealth_Jan201!=.
gen stockinvestor_ofin=riskshare_ofinwealth_Jan201>0 if riskshare_ofinwealth_Jan201!=.
gen delhhnetinc_USD_tr02alt_qtr_cond = delhhnetinc_USD_tr02alt_qtr if jobloss_20q1==1
gen del_hhnetinc_perc_tr02_cond = del_hhnetinc_perc_tr02 if jobloss_20q1==1
	
* Scale USD variables	
	foreach x in  delofin_USD_tr02 delretir_USD_tr02  delfinwealth_USD_tr02   delhhnetinc_USD_tr02 {
		replace `x' = `x'/1000
	}
	foreach x in ofinwealth_lvl retirewealth_lvl  finwealth_Jan20 hhinc_lvl hhnetinc_2019   {
		replace `x' = `x'/1000
	}

* gen conditional variables:
	gen del_ofin_perc_tr02_cond = del_ofin_perc_tr02
	replace del_ofin_perc_tr02_cond = . if stockinvestor_ofin!=1
	gen del_retir_perc_tr02_cond = del_retir_perc_tr02
	replace del_retir_perc_tr02_cond = . if stockinvestor_retire!=1
	gen del_finwealth_perc_tr02_cond = del_finwealth_perc_tr02
	replace del_finwealth_perc_tr02_cond = . if stockowner!=1

	gen delofin_USD_tr02_cond = delofin_USD_tr02
	replace delofin_USD_tr02_cond = . if stockinvestor_ofin!=1
	gen delretir_USD_tr02_cond = delretir_USD_tr02
	replace delretir_USD_tr02_cond = . if stockinvestor_retire!=1
	gen delfinwealth_USD_tr02_cond = delfinwealth_USD_tr02
	replace delfinwealth_USD_tr02_cond = . if stockowner!=1

* gen extensive margin vars:
	gen del_ofin_d = (del_ofin_perc_tr02<0) if  del_ofin_perc_tr02!=. 
	replace del_ofin_d = . if stockinvestor_ofin!=1
	
	gen del_retire_d = (del_retir_perc_tr02<0) if  del_retir_perc_tr02!=. 
	replace del_retire_d = . if stockinvestor_retire!=1
	
	gen del_finwealth_d = (del_finwealth_perc_tr02<0) if  del_finwealth_perc_tr02!=. 
	replace del_finwealth_d = . if stockowner!=1

	gen riskshare_5 = .
	replace riskshare_5=1 if riskshare_finwealth_Jan201>=0 &riskshare_finwealth_Jan201<=20 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=2 if riskshare_finwealth_Jan201>20 &riskshare_finwealth_Jan201<=40 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=3 if riskshare_finwealth_Jan201>40 &riskshare_finwealth_Jan201<=60 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=4 if riskshare_finwealth_Jan201>60 &riskshare_finwealth_Jan201<=80 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=5 if riskshare_finwealth_Jan201>80 &riskshare_finwealth_Jan201<=100 & riskshare_finwealth_Jan201!=.

	keep if control_pure==1	

	* JOB LOSS
	replace jobloss_20q1 = jobloss_20q1*100

	gen employment_type = employment_situation
	replace employment_type = . if employment_type!=1 & employment_type!=2 & employment_type!=9
	label values employment_type employment 		

	label define educationshort ///
	1 "Less HS" 2 "HS" 3 "Some col." 4 "Assoc." ///
	5 "Bach." 6 "Grad."
	label values education educationshort 
		
  *  by netwealth
	graph bar (mean)  jobloss_20q1 , ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5)) b1title(Net wealth quintile, size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(small)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(10)40, nogrid) saving(Figures/temp1.gph, replace)
		
 * by age	
	graph bar (mean)  jobloss_20q1 , ///
		over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(vsmall))) b1title(Age group, size(small) ) ///
		  bargap(0)  /// 
		ytitle("", size(small)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(10)40, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp2.gph, replace)
		
	* hh net income		
	graph bar (mean)  jobloss_20q1 , ///
		over(hhnetinc_2019_grp) b1title(Net income quintile, size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(10)40, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp3.gph, replace)
			
	* empoyment
	graph bar (mean)  jobloss_20q1 , ///
		over(employment_type,  relabel(1 "Full time" 2 "Part time" 3 "Self-emp" )  label(labsize(vsmall)))b1title("Employment type",  size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(small)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(10)40, nogrid)   saving(Figures/temp4.gph, replace)
		
	* change in fin wealth by hh net income		
	graph bar (mean)  jobloss_20q1, ///
		over(education, relabel(1 "Less HS" 2`" "High" "School" "'3 `" "Some"  "College" "' 4 `" "Assoc." "Deg." "'5 `" "Bach." "Deg." "'6 `" "Grad." "Deg." "') label(labsize(vsmall))) b1title("Highest level of education achieved",  size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(10)40, nogrid) saving(Figures/temp5.gph, replace) 
		
		* change in fin wealth by hh net income		
	graph bar (mean)  jobloss_20q1, ///
		over(gender, relabel(1 "Male" 2 "Female") label(labsize(vsmall))) b1title("Gender",  size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(10)40, nogrid) saving(Figures/temp6.gph, replace) 
			
		graph combine 	Figures/temp1.gph ///
						Figures/temp3.gph ///
						Figures/temp2.gph ///
						Figures/temp5.gph ///
						Figures/temp4.gph ///
						Figures/temp6.gph, cols(2) ysize(3) xsize(3) l1title("Lost job since January 2020 (%)", size(vsmall))

	graph export Figures/FigureA24.pdf, as(pdf) fontface("cmr10") replace
	graph export Figures/FigureA24.png, width(1600) replace	
	
	forvalues x = 1/6 {
		capture erase Figures/temp`x'.gph
}						
